package javolution.lang;

import cn.qqtheme.framework.adapter.FileAdapter;
import java.io.File;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javolution.util.StandardLog;

/* loaded from: classes2.dex */
public class ClassInitializer {
    private ClassInitializer() {
    }

    public static void initialize(Class cls) {
        try {
            Reflection.getClass(cls.getName());
        } catch (Throwable th) {
            StandardLog.error(th);
        }
    }

    public static void initialize(String str) {
        try {
            Reflection.getClass(str);
        } catch (ClassNotFoundException unused) {
            StandardLog.warning("Class + " + str + " not found");
        } catch (Throwable th) {
            StandardLog.error(th);
        }
    }

    private static void initialize(String str, File file) {
        String name = file.getName();
        if (file.isDirectory()) {
            File[] listFiles = file.listFiles();
            if (str.length() != 0) {
                name = str + FileAdapter.DIR_ROOT + name;
            }
            for (File file2 : listFiles) {
                initialize(name, file2);
            }
        } else if (name.endsWith(".class")) {
            String str2 = str + FileAdapter.DIR_ROOT + name.substring(0, name.length() - 6);
            StandardLog.finer("Initialize " + str2);
            initialize(str2);
        }
    }

    private static void initialize(String str, String str2) {
        String substring;
        StandardLog.fine("Initialize classpath: " + str);
        while (str.length() > 0) {
            int indexOf = str.indexOf(str2);
            if (indexOf < 0) {
                substring = "";
            } else {
                String substring2 = str.substring(0, indexOf);
                substring = str.substring(indexOf + str2.length());
                str = substring2;
            }
            if (str.endsWith(".jar") || str.endsWith(".zip")) {
                initializeJar(str);
            } else {
                initializeDir(str);
            }
            str = substring;
        }
    }

    public static void initializeAll() {
        initializeRuntime();
        initializeClassPath();
    }

    public static void initializeClassPath() {
        String property = System.getProperty("java.class.path");
        String property2 = System.getProperty("path.separator");
        if (property == null || property2 == null) {
            StandardLog.warning("Cannot initialize classpath through system properties");
        } else {
            initialize(property, property2);
        }
    }

    public static void initializeDir(String str) {
        StandardLog.fine("Initialize Directory: " + str);
        File file = new File(str);
        if (!file.getClass().getName().equals("java.io.File")) {
            StandardLog.warning("Initialization of classes in directory not supported for J2ME build");
        } else if (!file.isDirectory()) {
            StandardLog.warning(str + " is not a directory");
        } else {
            File[] listFiles = file.listFiles();
            for (File file2 : listFiles) {
                initialize("", file2);
            }
        }
    }

    public static void initializeJar(String str) {
        try {
            StandardLog.fine("Initialize Jar file: " + str);
            ZipFile zipFile = new ZipFile(str);
            if (!zipFile.getClass().getName().equals("java.util.zip.ZipFile")) {
                StandardLog.warning("Initialization of classes in jar file not supported for J2ME build");
                return;
            }
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                String name = entries.nextElement().getName();
                if (name.endsWith(".class")) {
                    String replace = name.substring(0, name.length() - 6).replace('/', '.');
                    StandardLog.finer("Initialize " + replace);
                    initialize(replace);
                }
            }
        } catch (Exception e) {
            StandardLog.error(e);
        }
    }

    public static void initializeRuntime() {
        String str;
        String property = System.getProperty("sun.boot.class.path");
        String property2 = System.getProperty("path.separator");
        if (property == null || property2 == null) {
            str = "Cannot initialize boot path through system properties";
        } else {
            initialize(property, property2);
            String property3 = System.getProperty("java.home");
            String property4 = System.getProperty("file.separator");
            if (property3 == null || property4 == null) {
                str = "Cannot initialize extension library through system properties";
            } else {
                File file = new File(property3 + property4 + "lib" + property4 + "ext");
                if (file.getClass().getName().equals("java.io.File")) {
                    if (!file.isDirectory()) {
                        StandardLog.warning(file + " is not a directory");
                        return;
                    }
                    for (File file2 : file.listFiles()) {
                        String path = file2.getPath();
                        if (path.endsWith(".jar") || path.endsWith(".zip")) {
                            initializeJar(path);
                        }
                    }
                    return;
                }
                str = "Extension classes initialization not supported for J2ME build";
            }
        }
        StandardLog.warning(str);
    }
}
